package com.ruoyi.temu.service.impl;

import java.util.*;


import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.temu.domain.*;
import com.ruoyi.temu.mapper.TemuSkuMapper;
import com.ruoyi.temu.mapper.TemuSpuMapper;
import com.ruoyi.temu.mapper.TemuSubPurchaseOrderMapper;
import com.ruoyi.temu.mapper.TemuSubPurchaseOrderSkuMapper;
import com.ruoyi.temu.service.ITemuService;
import okhttp3.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.function.Function;
import java.util.stream.Collectors;


@Service
public class TemuServiceImpl implements ITemuService {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    private static final String antiContent = "0aqAfqnygjSgjgT9l07gek7CbCJNv0zzoK-ualY8r_jy4TzSrdFj-0_diU-krGfDMkDDl5Qtv_sk4Rt1A0nTYJy7IjS0rd2-y1VycPWPS_8nIzzSSjkxPlpyIQPBaZBEwr0YGg-T-0q30qOoPXuVZo8F8xab6-vPvl8Jj0kk6C95oai4Ad53YEemHa8981WBpfKRob6LPwO083hXAT7JEvKOPrlShhyt3pwDRC-cUuJSPrcS5uI0tMwD_ZVvDSsyRC6cCBYL21OoCtLT5a2tIKXQNPLRS1RVJjyZDL0BiHX1k0J0JyG4RCZ7Envi4vi0AOS-_3067j2FR0zFbEv-gPDBYi2YY__nrVLrnUNrRzpF-7-8MURMeupkZD2-zS-M5mocfZVNr1HeMC5BjAq0FJlq9-ssPNaeGStfbSy8lxxcj8_tPVcFi91Ag_Moq-jEAL_8FxOCV91ugvMfSffAdouBqk5w1NxI-1kYPcmonS5lXdEqDsiEuEKmgP6Zo7fyNBl_Kbzj-Ak-VfwVMKdZxWuIexDEcyio70h3DlHK1EviSP__xHOD44en7_suYSFp-CNi1KN7mL1wjNti15eW_ULItmqEIAH4zBhsV3XRlnLLlfCPlcG5WH6Vh1itpM_vaYhYIhmhLRvdqxGdaZmkZ-lxcdAMTISA5LIiNu4jNq2RPVW0I5Q7agFl5OMY5jOcOXReYciThb4ezWHkPaVAHda";


    private static final String cookie = "_f77=43f7375e-cdd9-4bdc-b38d-319f9b278836; _bee=dNOmt1zW9VW5iwQGW0leaJWlzd98lLJl; _a42=38f0ed14-1cf3-4e1e-9bb6-0e1b12da62da; api_uid=CmmurmRcPVpYdwBaC3DQAg==; _nano_fp=XpEJXqmjn5Eal0T8lT_gBdmPI_CrAczBYbR8jaWN; rckk=dNOmt1zW9VW5iwQGW0leaJWlzd98lLJl; ru1k=43f7375e-cdd9-4bdc-b38d-319f9b278836; ru2k=38f0ed14-1cf3-4e1e-9bb6-0e1b12da62da; SUB_PASS_ID=eyJ0IjoiU1dEQlFJZzZOcm1Ld0JpYUhPbk82bnUxSU16ZXZCTWt5TGRLNGtXaldSdjJHVUVwN2V6QndVbUZNMlBkbFRVeiIsInYiOjEsInMiOjEwMDAwLCJ1Ijo5MDQ2ODAyNDAxMzI5fQ==";

    @Resource
    private TemuSpuMapper temuSpuMapper;

    @Resource
    private TemuSkuMapper temuSkuMapper;

    @Resource
    private TemuSubPurchaseOrderMapper temuSubPurchaseOrderMapper;

    @Resource
    private TemuSubPurchaseOrderSkuMapper temuSubPurchaseOrderSkuMapper;


    private QuerySpuResponse querySpu(QuerySpuRequest querySpuRequest) {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/json");

        String str = JSONObject.toJSONString(querySpuRequest);
        System.out.println(str);
        RequestBody body = RequestBody.create(str, mediaType);

        Request request = new Request.Builder()
                .url("https://kuajing.pinduoduo.com/marvel-supplier/api/xmen/select/search")
                .method("POST", body)
                .addHeader("authority", "kuajing.pinduoduo.com")
                .addHeader("accept", "*/*")
                .addHeader("accept-language", "zh-CN,zh;q=0.9")
                .addHeader("anti-content", "0aqWfqnF0jKgJgExceWWb5Gs0WSuMb1MQcPMOcA_LsfGskH_LY21sl3foer_l3qL_zZpDAPDkcg5ezU5AB4KI2zvqM8pUIdjIFb46saIFnujg62tMVlSg7W2JraCo0aQcVsTlzQvrslmLvZc8W68Ogn9oodsMbpRg9iaYug8cw0m26b_cJ0nKs0IKFe4sYB2ckdzX9Ln-vErB2pZWdlA-_KbMjN1Nfv7XWQtIYV9eqMa5KRa_dnmh2YmB5aZIexFTkJN48Ryl9h6h4W2hobBvOhohXSsreayfJixIKl0vqVMYHduksRIOXc7tDJAm5ln71QZ8hbTHe7bTHW1nOLj64neIM0RinhBFLL7X19NhdHpVHIZdPhJNixMDt_nHPDMYlqIDGAgkhyGu3_U4xSlqS5W4y-I8UgzJTyFF8zK6tOWz_KJsy3lcPUqffQ0OIqgfTFSNe6WavwiOhqSxuFXw5P-Ku_UaNIK-Pq_UQdS0jMYxhMI792-MuNNELmQkcSxMlXaGQN9nn156y0YfYEjNhguUMpxXSyIs6V9obVLxukYRZPmlYNtuEyXKT3T3Pkh3WfLP3cgdbTwfkJ5rMKIP1Ue0y1Wxt3b7lfB_hA0TaHfZRpYn5dsF3kymnpg_WdS9iQpFiPD_dR7oSoYv78JLS-_DsVg53osPU7pC0R5EZ-swjHPZMi-fcXYEDv5QeyZk98lGUwoA-vXj1CRoCZ0RqPjzlQb7Hse")
                .addHeader("cache-control", "max-age=0")
                .addHeader("content-type", "application/json")
                .addHeader("cookie", "_f77=43f7375e-cdd9-4bdc-b38d-319f9b278836; _bee=dNOmt1zW9VW5iwQGW0leaJWlzd98lLJl; _a42=38f0ed14-1cf3-4e1e-9bb6-0e1b12da62da; api_uid=CmmurmRcPVpYdwBaC3DQAg==; _nano_fp=XpEJXqmjn5Eal0T8lT_gBdmPI_CrAczBYbR8jaWN; rckk=dNOmt1zW9VW5iwQGW0leaJWlzd98lLJl; ru1k=43f7375e-cdd9-4bdc-b38d-319f9b278836; ru2k=38f0ed14-1cf3-4e1e-9bb6-0e1b12da62da; SUB_PASS_ID=eyJ0IjoiSTVtYmZKV2o5alVMWXp4NCs5U0NCSElkY0xwcEVuN1FYWUFRSnVOaktXTGs5dWJidlJaU0E4MmNKV2ovTzRZeiIsInYiOjEsInMiOjEwMDAwLCJ1Ijo5MDQ2ODAyNDAxMzI5fQ==")
                .addHeader("mallid", "634418210372218")
                .addHeader("origin", "https://kuajing.pinduoduo.com")
                .addHeader("referer", "https://kuajing.pinduoduo.com/main/product/seller-select")
                .addHeader("sec-ch-ua", "\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\"")
                .addHeader("sec-ch-ua-mobile", "?0")
                .addHeader("sec-ch-ua-platform", "\"Windows\"")
                .addHeader("sec-fetch-dest", "empty")
                .addHeader("sec-fetch-mode", "cors")
                .addHeader("sec-fetch-site", "same-origin")
                .addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36")
                .build();

        try {
            Response response = client.newCall(request).execute();
//            System.out.println(response.body().string());

            return JSONObject.parseObject(response.body().string(), QuerySpuResponse.class);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    /**
     * 操作流程，从temu中获取商品列表，然后填入数据库
     * TODO yxt 解决翻页问题
     *
     * @return
     */
    @Override
    public int syncProductFromTemu() {
        int page = 1;
        int size = 100;
        int dataSize;

        do {
            dataSize = -1;
            QuerySpuRequest request = new QuerySpuRequest();
            request.setPageNum(page++);
            request.setPageSize(size);
            //        request.setPriceReviewStatusList(Collections.EMPTY_LIST);
            //        request.setSecondarySelectStatusList();
            request.setSupplierTodoTypeList(Collections.EMPTY_LIST);

            QuerySpuResponse querySpuResponse = querySpu(request);


            System.out.println(JSONObject.toJSONString(querySpuResponse));

            if (querySpuResponse.getSuccess() && querySpuResponse.getErrorCode() == 1000000) {
                QuerySpuResponse.ResultDTO result = querySpuResponse.getResult();

                List<QuerySpuResponse.ResultDTO.DataListDTO> spuList = result.getDataList();
                dataSize = spuList.size();
                for (QuerySpuResponse.ResultDTO.DataListDTO spuDTO : spuList) {
                    // 查询到订单列表以后
                    List<QuerySpuResponse.ResultDTO.DataListDTO.SkcListDTO> skcList = spuDTO.getSkcList();
                    QuerySpuResponse.ResultDTO.DataListDTO.SkcListDTO skcDTO = skcList.get(0);

                    TemuSpu temuSpu = temuSpuMapper.selectTemuSpuBySpuId(spuDTO.getProductId());
                    if (temuSpu == null) {
                        // add
                        temuSpu = new TemuSpu();
                        temuSpu.setSpuId(spuDTO.getProductId());
                        temuSpu.setSupplierId(spuDTO.getSupplierId());
                        temuSpu.setProductCreatedAt(new Date(spuDTO.getProductCreatedAt()));
                        temuSpu.setProductUpdatedAt(new Date(spuDTO.getProductUpdatedAt()));
                        temuSpu.setSpuName(spuDTO.getProductName());
                        temuSpu.setSelectStatus(skcDTO.getSelectStatus().longValue());
                        temuSpu.setSkcId(skcDTO.getSkcId());
                        temuSpu.setCarouselImageUrlList(StringUtils.join(spuDTO.getCarouselImageUrlList(), ",")); // 将图片变成Json存入数据库
                        temuSpuMapper.insertTemuSpu(temuSpu);
                    } else {
                        // try update
                        temuSpu.setProductUpdatedAt(new Date(spuDTO.getProductUpdatedAt()));
                        if (skcDTO != null) {
                            temuSpu.setSelectStatus(skcDTO.getSelectStatus().longValue());
                            temuSpu.setSkcId(skcDTO.getSkcId());
                        }
                        temuSpuMapper.updateTemuSpu(temuSpu);
                    }

                    // 然后更新sku列表


                    List<QuerySpuResponse.ResultDTO.DataListDTO.SkcListDTO.SkuListDTO> skuList = skcDTO.getSkuList();
                    if (CollectionUtils.isNotEmpty(skuList)) {
                        for (QuerySpuResponse.ResultDTO.DataListDTO.SkcListDTO.SkuListDTO skuDTO : skuList) {
                            TemuSku temuSku = temuSkuMapper.selectTemuSkuBySkuId(skuDTO.getSkuId());
                            if (temuSku == null) {
                                // add
                                TemuSku insertSku = new TemuSku();
                                insertSku.setSpuId(spuDTO.getProductId());
                                insertSku.setSkuId(skuDTO.getSkuId());
                                insertSku.setSkcId(skcDTO.getSkcId());
                                insertSku.setProductPropertyList(JSONObject.toJSONString(skuDTO.getProductPropertyList()));
                                insertSku.setSupplierPrice(skuDTO.getSupplierPrice());
                                insertSku.setExtCode(skuDTO.getExtCode());
                                insertSku.setLen(skuDTO.getLen().toString());
                                insertSku.setWidth(skuDTO.getWidth().longValue());
                                insertSku.setHeight(skuDTO.getHeight().longValue());
                                insertSku.setWeight(skuDTO.getWeight().longValue());
                                insertSku.setSkuPreviewImage(skuDTO.getSkuPreviewImage());

                                temuSkuMapper.insertTemuSku(insertSku);
                            } else {
                                // TODO 暂时没有要更新的
                            }
                        }
                    }
                }
            }
        } while (dataSize == size);

        return 0;
    }

    @Override
    public int syncSubPurchaseOrderFromTemu() {
        //
        int page = 1;
        int size = 200;
        int dataSize;

        do {
            dataSize = -1;

            QuerySubOrderListRequest request = new QuerySubOrderListRequest();
            request.setPageNo(page ++);
            request.setPageSize(size);
            request.setUrgencyType(0);
            request.setIsCustomGoods(false);
            QuerySubOrderListResponse querySubOrderListResponse = querySubOrderList(request);
            // 没有就写入数据库，有就更新数据

            if (querySubOrderListResponse.getSuccess()) {
                List<QuerySubOrderListResponse.ResultDTO.SubOrderForSupplierListDTO> subOrderForSupplierList = querySubOrderListResponse.getResult().getSubOrderForSupplierList();
                dataSize = subOrderForSupplierList.size();

                for (QuerySubOrderListResponse.ResultDTO.SubOrderForSupplierListDTO subOrderDTO : subOrderForSupplierList) {
                    String subPurchaseOrderSn = subOrderDTO.getSubPurchaseOrderSn();
                    TemuSubPurchaseOrder temuSubPurchaseOrder =
                            temuSubPurchaseOrderMapper.selectTemuSubPurchaseOrderBySubPurchaseOrderSn(subPurchaseOrderSn);

                    if (temuSubPurchaseOrder == null) {
                        // insert
                        TemuSubPurchaseOrder temuSubPurchaseOrderInsert = new TemuSubPurchaseOrder();
                        temuSubPurchaseOrderInsert.setSubPurchaseOrderSn(subPurchaseOrderSn);
                        temuSubPurchaseOrderInsert.setOriginalPurchaseOrderSn(subOrderDTO.getOriginalPurchaseOrderSn());
                        temuSubPurchaseOrderInsert.setSupplierId(634418210372218L);
                        temuSubPurchaseOrderInsert.setProductName(subOrderDTO.getProductName());
                        temuSubPurchaseOrderInsert.setSpuId(subOrderDTO.getProductId());
                        temuSubPurchaseOrderInsert.setSkcId(subOrderDTO.getProductSkcId());
                        temuSubPurchaseOrderInsert.setSkcPicture(subOrderDTO.getProductSkcPicture());
                        temuSubPurchaseOrderInsert.setStatus(subOrderDTO.getStatus().longValue());

                        //
                        List<TemuSubPurchaseOrderSku> insertSkuList = subOrderDTO.getSkuQuantityDetailList().stream().map(detail -> {
                            TemuSubPurchaseOrderSku sku = new TemuSubPurchaseOrderSku();
                            sku.setSubPurchaseOrderSn(subPurchaseOrderSn);
                            sku.setSkuId(detail.getProductSkuId());
                            sku.setExtCode(detail.getExtCode());
                            sku.setSupplierPrice(detail.getSupplierPrice());
                            sku.setPurchaseQuantity(detail.getPurchaseQuantity());
                            sku.setDeliverQuantity(detail.getDeliverQuantity());
                            sku.setRealReceiveAuthenticQuantity(detail.getRealReceiveAuthenticQuantity());
                            sku.setThumbUrl(detail.getThumbUrlList().get(0));
                            return sku;
                        }).collect(Collectors.toList());
                        temuSubPurchaseOrderInsert.setTemuSubPurchaseOrderSkuList(insertSkuList);

                        temuSubPurchaseOrderMapper.insertTemuSubPurchaseOrder(temuSubPurchaseOrderInsert);
                        temuSubPurchaseOrderMapper.batchTemuSubPurchaseOrderSku(insertSkuList);
                    }else{
                        // update
                        // 主要是更新入库数量，以及订单的状态
                        temuSubPurchaseOrder.setStatus(subOrderDTO.getStatus().longValue());

                        List<TemuSubPurchaseOrderSku> temuSubPurchaseOrderSkuList = temuSubPurchaseOrder.getTemuSubPurchaseOrderSkuList();

                        Map<Long/*skuId*/,
                                QuerySubOrderListResponse.ResultDTO.SubOrderForSupplierListDTO.SkuQuantityDetailListDTO> map = subOrderDTO.getSkuQuantityDetailList().stream().collect(Collectors.toMap(QuerySubOrderListResponse.ResultDTO.SubOrderForSupplierListDTO.SkuQuantityDetailListDTO::getProductSkuId, Function.identity()));

                        for (TemuSubPurchaseOrderSku temuSubPurchaseOrderSku : temuSubPurchaseOrderSkuList) {
                            if (map.containsKey(temuSubPurchaseOrderSku.getSkuId())){
                                // 有就更新
                                QuerySubOrderListResponse.ResultDTO.SubOrderForSupplierListDTO.SkuQuantityDetailListDTO skuQuantityDetailListDTO = map.get(temuSubPurchaseOrderSku.getSkuId());

                                temuSubPurchaseOrderSku.setPurchaseQuantity(skuQuantityDetailListDTO.getPurchaseQuantity());
                                temuSubPurchaseOrderSku.setDeliverQuantity(skuQuantityDetailListDTO.getDeliverQuantity());
                                temuSubPurchaseOrderSku.setRealReceiveAuthenticQuantity(skuQuantityDetailListDTO.getRealReceiveAuthenticQuantity());
                                temuSubPurchaseOrderSkuMapper.updateTemuSubPurchaseOrderSku(temuSubPurchaseOrderSku);
                            }
                        }
                        temuSubPurchaseOrderMapper.updateTemuSubPurchaseOrder(temuSubPurchaseOrder);
                    }
                }
            }
            // 然后还需要修改

        } while (dataSize == size);
        return 0;
    }

    @Override
    public int syncBuyUrlFromMango(String strResponse) {
        QueryMangoUrlResponse queryMangoUrlResponse = JSONObject.parseObject(strResponse, QueryMangoUrlResponse.class);

        List<QueryMangoUrlResponse.DataDTO.ListDTO> list = queryMangoUrlResponse.getData().getList();

        Map</*名称*/String, /*url*/String> nameUrlMap = list.stream()
                .map(dto -> {
                    dto.setOnlineUrl(dto.getOnlineUrl().split("\\?")[0]);
                    return dto;
                })
                .filter(dto -> StringUtils.isNotEmpty(dto.getOnlineUrl()))
                .collect(Collectors.toMap(QueryMangoUrlResponse.DataDTO.ListDTO::getProductName, QueryMangoUrlResponse.DataDTO.ListDTO::getOnlineUrl, (n1, n2) -> n1));


        // 打印一下
        nameUrlMap.forEach((k, v) -> {
            System.out.println("k:" + k + " v:" + v);
        });

        // 获取所有url为空的spu
        List<TemuSpu> temuSpus = temuSpuMapper.selectTemuSpuList(new TemuSpu());

        logger.info("temuspus.size:" + temuSpus.size());

        temuSpus.stream()
                .forEach(temuSpu -> {
                    // 有地址就更新
                    if (nameUrlMap.containsKey(temuSpu.getSpuName())) {
                        String url = nameUrlMap.get(temuSpu.getSpuName());
                        temuSpu.setBuyUrl(url);
                        logger.info(temuSpu.getSpuName() + " 需要更新url:" + temuSpu.getBuyUrl());
                        temuSpuMapper.updateTemuSpu(temuSpu);
                    } else {
                        logger.info(temuSpu.getSpuName() + " 暂时更新不了");

                    }
                });
        return 0;
    }


    /**
     * 备货单列表查询,可以参与库存的统计，讲备货单同步到系统中，用来统计发货出去的情况
     */
    private QuerySubOrderListResponse querySubOrderList(QuerySubOrderListRequest queryRequest) {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        String str = JSONObject.toJSONString(queryRequest);
        System.out.println(str);
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, str);
        Request request = new Request.Builder()
                .url("https://kuajing.pinduoduo.com/oms/bg/venom/api/supplier/purchase/manager/querySubOrderList")
                .method("POST", body)
                .addHeader("authority", "kuajing.pinduoduo.com")
                .addHeader("accept", "*/*")
                .addHeader("accept-language", "zh-CN,zh;q=0.9")
                .addHeader("anti-content", "0aqWfqAyXjHgjgT9Q4n05iWw9TQSOKtWyU2k0uM8zaO-_exztycOTDp75qoqk1OO1oAmZGLuTKdktMVwDSBeUs_ZXTMe1BP1vGNTPFWI5f4ww4Qru802LyVpO9ETlTnEPkZZM6WmZo0rsHk7qmYNGSfXW8hDEmJendb351DTWCT2SKsmAu33Hfi9Ymw_Em7OPvDi-CagrjKCaSzQeLkOmR94oImQPdLhFQzbp6LSDx2BEjBvMgpJ_ec8gtEFZ7bV7bVpm4zlWenIdgsCdrhTVjAPyha5HmP6z5U0yFvQIgQyB8y5WLVA7PmkZOuOyTzeTsAfGAVBkyS4E9gcuVn8g2Sq67bVSehEKdWL5_nRxqp76oB_NuqxDfwlXHYhwGntoMyqj0qIktlbdHIBIiwfuEHkFK8SwHnyrwONKzXeM2p8IFIZ_fUrmjfROHrH0Ji7w3QPl4pfnNwHq_tCIEFAPO2Sjia4aBEL2zU3mbgEwZOy_--Dca8ITEIybIIdcrSg-Z66fCIgav8tXDL2kCTa8f2iQDaFLtJMayDZ5H63mg21uUrQ6L7w8TA9E8xaAl6zv7fqWaflkSphi-axcTjM7WrwkCTWWxkWKBDqcRwO5nZwgb-xHvOJZWZIZ4pjnZKl1p_K5A6a8ealwyDBwhzOUTRkQjY3jYFEYNofwAqCntdDvBh6VxHzOSdZ1QwuNkPD5fga3rUkbG1JcLLb3sciMJjEPsJY2RXTQ94IXLcgaE")
                .addHeader("cache-control", "max-age=0")
                .addHeader("content-type", "application/json")
                .addHeader("cookie", "_f77=43f7375e-cdd9-4bdc-b38d-319f9b278836; _bee=dNOmt1zW9VW5iwQGW0leaJWlzd98lLJl; _a42=38f0ed14-1cf3-4e1e-9bb6-0e1b12da62da; api_uid=CmmurmRcPVpYdwBaC3DQAg==; _nano_fp=XpEJXqmjn5Eal0T8lT_gBdmPI_CrAczBYbR8jaWN; rckk=dNOmt1zW9VW5iwQGW0leaJWlzd98lLJl; ru1k=43f7375e-cdd9-4bdc-b38d-319f9b278836; ru2k=38f0ed14-1cf3-4e1e-9bb6-0e1b12da62da; SUB_PASS_ID=eyJ0Ijoib1RyWXZMZWI1ejFhT215SzdrRUJodzNDTVVORUs4QUFRQ3N2RTNEYVhPZ0RXUTN6WEtnWTNXdVZtSmNaaVBtZiIsInYiOjEsInMiOjEwMDAwLCJ1Ijo5MDQ2ODAyNDAxMzI5fQ==")
                .addHeader("mallid", "634418210372218")
                .addHeader("origin", "https://kuajing.pinduoduo.com")
                .addHeader("referer", "https://kuajing.pinduoduo.com/main/order-manage")
                .addHeader("sec-ch-ua", "\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\"")
                .addHeader("sec-ch-ua-mobile", "?0")
                .addHeader("sec-ch-ua-platform", "\"Windows\"")
                .addHeader("sec-fetch-dest", "empty")
                .addHeader("sec-fetch-mode", "cors")
                .addHeader("sec-fetch-site", "same-origin")
                .addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36")
                .build();
        try {
            Response response = client.newCall(request).execute();

            return JSONObject.parseObject(response.body().string(), QuerySubOrderListResponse.class);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
